package com.smart.car.member.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;


/**
 *
 * TODO 单个项目下的swagger可以这样配置。
 * TODO 不管是knife4j还是swagger-bootstrap-ui,对外提供的地址依然是doc.html
 * TODO 读取配置文件中前缀为swagger2的配置，属性名为enable，值为true时，此配置类才被激活。
 * @author: zoutao
 * @date: 2021-04-22
 */
@EnableSwagger2WebMvc
@Configuration
@ConditionalOnProperty(prefix = "knife4j",value = {"enable"},havingValue = "true")
public class SwaggerConfig {

    // 创建swagger-api和基本信息
    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("Member用户微服务接口api文档")
                        .description("<div style='font-size:14px;color:red;'>景停系统API管理系统</div>")
                        .termsOfServiceUrl("http://www.iszoutao.com/")
                        .contact("iszoutao@gmail.com")
                        .version("2.0.8版本")
                        .build())
                //分组名称-关系到网关的配置！
                .groupName("default")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.smart.car.member.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

}
